<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>后盾人</title>
  </head>
  <body></body>
  <script src="js/ajax.js"></script>
  <script>
    // function hd() {}
    // hd.site = "houdunren.com";
    // console.dir(hd);
    Promise.hd = function(value) {
      return new Promise(resolve => {
        resolve(value);
      });
    };
    Promise.hd("后盾人").then(value => {
      console.log(value);
    });
    function query(name) {
      const cache = query.cache || (query.cache = new Map());
      if (cache.has(name)) {
        console.log("走缓存了");
        return Promise.resolve(cache.get(name));
      }
      return ajax(`http://localhost:8888/php/user.php?name=${name}`).then(
        user => {
          cache.set(name, user);
          console.log("没走缓存");
          return user;
        }
      );
    }
    // query("后盾人").then(user => {
    //   console.log(user);
    // });
    // query("后盾人").then(user => {
    //   console.log(user);
    // });
    // setTimeout(() => {
    //   query("后盾人").then(user => {
    //     console.log(user);
    //   });
    // }, 1000);
    // setTimeout(() => {
    //   query("后盾人").then(user => {
    //     console.log(user);
    //   });
    // }, 1000);
    // console.log(Promise.resolve("后盾人"));
    // Promise.resolve("后盾人").then(value => {
    //   console.log(value);
    // });
  </script>
</html>
